﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}


<br />
<table id="customers" class="table table-bordered table-hover">
    <thead>
        <tr>
            <th>FirstName</th>
            <th>Last Name</th>
            <th>MembershipType</th>

        </tr>
    </thead>
    <tbody></tbody>
</table>


@section scripts
{
    <script>
        $(document)
            .ready(function() {

                var table = $("#customers")
                    .DataTable(
                        {
                            ajax: {
                                url: "/api/customers",
                                dataSrc: ""
                            },
                            columns: [
                                {
                                    data: "FirstName"
                                },
                                {
                                    data: "LastName"
                                },
                                {
                                    data: "MembershipType.Name"
                                }

                ]
            });

        $("#customers")
            .on("click",
                ".js-delete",
                function() {
                    var button = $(this);

                    bootbox.confirm("Do you realy want to delete customer?",
                        function(result) {
                            if (result) {
                                $.ajax({
                                    url: "/api/customers/" + button.attr("data-customer-id"),
                                    method: "DELETE",
                                    success: function() {
                                        button.parents("tr").remove();
                                    }
                                });
                            }
                        });


                });
        });
    </script>
    @Scripts.Render("~/bundles/datatable")
}